home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / os2 / pc2_140.zip / SOURCE.ZIP / Source / Dialog.c next >
C/C++ Source or Header  |  1993-04-17  |  68KB  |  1,203 lines

  1. /***********************************************************************\
  2.  *                                PC2.c                                *
  3.  *                 Copyright (C) by Stangl Roman, 1993                 *
  4.  * This Code may be freely distributed, provided the Copyright isn't   *
  5.  * removed, under the conditions indicated in the documentation.       *
  6.  *                                                                     *
  7.  * Dialog.c     Dialog window procedures.                              *
  8.  *                                                                     *
  9. \***********************************************************************/
  10.  
  11. static char RCSID[]="@(#) $Header: Dialog.c Version 1.40 04,1993 $ (LBL)";
  12.  
  13. #define         _FILE_  "PC/2 - Dialog.c V1.40"
  14.  
  15. #include        "PC2.h"                 /* User include files */
  16. #include        "Error.h"
  17.  
  18. PFNWP           PI_ClassDialogProcedure;
  19.  
  20. /*--------------------------------------------------------------------------------------*\
  21.  * This dialog procedure handles the PC/2 - About dialog.                               *
  22.  * Req: none                                                                            *
  23. \*--------------------------------------------------------------------------------------*/
  24. MRESULT  EXPENTRY AD_DialogProcedure(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  25. {
  26. switch(msg)
  27. {
  28. case WM_INITDLG:
  29.     {
  30.     SWP         swp;
  31.  
  32.     WinQueryWindowPos(                  /* Query position of dialog window */
  33.         hwndDlg,                        /* Handle of dialog window */
  34.         &swp);                          /* Fill with position */
  35.     WinSetWindowPos(                    /* Set dialog window position */
  36.         hwndDlg,                        /* Handle of dialog window */
  37.         HWND_TOP,                       /* Position on top and center of DESKTOP */
  38.         (swpScreen.cx-swp.cx)/2, (swpScreen.cy-swp.cy)/2, 0, 0, SWP_MOVE);
  39.     break;
  40.     }
  41.  
  42. case WM_HELP:                           /* Help pressed */
  43.     if(hwndHelp!=NULLHANDLE) WinSendMsg(
  44.         hwndHelp,                       /* Help window */
  45.         HM_DISPLAY_HELP,                /* Display a help panel */
  46.         MPFROMSHORT(ID_ABOUTDIALOG),    /* Panel ID in ressource file */
  47.         HM_RESOURCEID);                 /* MP1 points to the help window identity */
  48.     break;
  49.  
  50. case WM_COMMAND:                        /* Button pressed */
  51.     switch(SHORT1FROMMP(mp1))
  52.     {
  53.     case DID_OK:                        /* Enter key pressed */
  54.         DialogResult=DID_OK;            /* Dialog terminated with DID_OK */
  55.         break;
  56.  
  57.     case DID_CANCEL:                    /* Cancel key pressed */
  58.         DialogResult=DID_CANCEL;        /* Dialog terminated with DID_CANCEL */
  59.         break;
  60.  
  61.     default:
  62.         return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  63.     }
  64.     WinDismissDlg(hwndDlg, TRUE);       /* Clear up dialog */
  65.     break;
  66.  
  67. default:                                /* Default window procedure must be called */
  68.     return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  69. }
  70. return((MRESULT)FALSE);                 /* We have handled the message */
  71. }
  72.  
  73. /*--------------------------------------------------------------------------------------*\
  74.  * This dialog procedure handles the PC/2 - Program Installation dialog.                *
  75.  * Req:                                                                                 *
  76.  *      StartSession .. a structure of type SESSIONDATA where the information entered   *
  77.  *                      in the dialog is entered. If DID_OK is pressed this structure   *
  78.  *                      is used to start the session and set its priority.              *
  79. \*--------------------------------------------------------------------------------------*/
  80. MRESULT  EXPENTRY PI_DialogProcedure(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  81. {
  82. switch(msg)
  83. {
  84. case WM_INITDLG:
  85.     {
  86.     SWP         swp;
  87.  
  88.     WinQueryWindowPos(                  /* Query position of dialog window */
  89.         hwndDlg,                        /* Handle of dialog window */
  90.         &swp);                          /* Fill with position */
  91.     WinSetWindowPos(                    /* Set dialog window position */
  92.         hwndDlg,                        /* Handle of dialog window */
  93.         HWND_TOP,                       /* Position on top and center of DESKTOP */
  94.         (swpScreen.cx-swp.cx)/2, (swpScreen.cy-swp.cy)/2, 0, 0, SWP_MOVE);
  95. /*                                                                                      *\
  96.  * Set the maximum number of chars accepted from the entryfield (thus overwriting the   *
  97.  * default number of 63 and load the data from the SESSIONDATA structure SessionData    *
  98.  * into the entryfields.                                                                *
  99. \*                                                                                      */
  100.     WinSendDlgItemMsg(                  /* Send message to dialog window */
  101.         hwndDlg,                        /* Handle of dialog window */
  102.         PIEF_PROGRAMTITLE,              /* Program title entryfield */
  103.         EM_SETTEXTLIMIT,                /* Set text limit to 60 */
  104.         MPFROMSHORT(EF_SIZE60),
  105.         (MPARAM)NULL);                  /* No additional parameter */
  106.     WinSetDlgItemText(                  /* Load the default text of the entryfield */
  107.         hwndDlg, PIEF_PROGRAMTITLE, SessionData.PgmTitle);
  108.     WinSendDlgItemMsg(
  109.         hwndDlg,
  110.         PIEF_PATHFILENAME,              /* Path and Filename title entryfield */
  111.         EM_SETTEXTLIMIT,                /* Set text limit to 255 */
  112.         MPFROMSHORT(EF_SIZE255),
  113.         (MPARAM)NULL);
  114.     WinSetDlgItemText(hwndDlg, PIEF_PATHFILENAME, SessionData.PgmName);
  115.     WinSendDlgItemMsg(
  116.         hwndDlg,
  117.         PIEF_DIRECTORY,                 /* Working directory entryfield */
  118.         EM_SETTEXTLIMIT,                /* Set text limit to 255 */
  119.         MPFROMSHORT(EF_SIZE255),
  120.         (MPARAM)NULL);
  121.     WinSetDlgItemText(hwndDlg, PIEF_DIRECTORY, SessionData.PgmDirectory);
  122.     WinSendDlgItemMsg(
  123.         hwndDlg,
  124.         PIEF_PARAMETERS,                /* Program Parameters entryfield */
  125.         EM_SETTEXTLIMIT,                /* Set text limit to 255 */
  126.         MPFROMSHORT(EF_SIZE255),
  127.         (MPARAM)NULL);
  128.     WinSetDlgItemText(hwndDlg, PIEF_PARAMETERS, SessionData.PgmInputs);
  129.                                         /* Insert DOS Settings. If none exist add the
  130.                                            IDLE_* default settings */
  131.     if(strlen(SessionData.PgmDosSettings)!=0)
  132.         WinSendDlgItemMsg(
  133.             hwndDlg,
  134.             PIEF_DOSSETTINGS,           /* Program DOS Settings entryfield */
  135.             MLM_INSERT,                 /* Insert text */
  136.             MPFROMP(SessionData.PgmDosSettings),
  137.             (MPARAM)NULL);
  138.     else
  139.         WinSendDlgItemMsg(
  140.             hwndDlg,
  141.             PIEF_DOSSETTINGS,           /* Program DOS Settings entryfield */
  142.             MLM_INSERT,                 /* Insert text */
  143.             MPFROMP("IDLE_SECONDS=5\nIDLE_SENSITIVITY=100\n"),
  144.             (MPARAM)NULL);
  145. /*                                                                                      *\
  146.  * Now we preselect the radiobutton in the Program type group to the state indicated by *
  147.  * the SessionData structure.                                                           *
  148. \*                                                                                      */
  149.     WinSendMsg(hwndDlg, WM_SETUPPROGRAMTYPE,
  150.         MPFROMSHORT(SessionData.SessionType), (MPARAM)NULL);
  151. /*                                                                                      *\
  152.  * Now we preselect the radiobutton in the Program style group to the state indicated   *
  153.  * by the SessionData structure.                                                        *
  154. \*                                                                                      */
  155.     if(!(SessionData.PgmControl & (SSF_CONTROL_MAXIMIZE | SSF_CONTROL_MINIMIZE)))
  156.         WinSendDlgItemMsg(              /* Send message to Default radiobutton */
  157.             hwndDlg,                    /* Handle of dialog window */
  158.             PIRB_DEFAULTSTYLE,          /* Program style: Default radiobutton */
  159.             BM_SETCHECK,                /* Set it to pressed */
  160.             MPFROMSHORT(TRUE),
  161.             (MPARAM)NULL);
  162.     if(SessionData.PgmControl & SSF_CONTROL_MAXIMIZE)
  163.         WinSendDlgItemMsg(
  164.             hwndDlg,
  165.             PIRB_MAXIMIZED,             /* Program style: Maximized radiobutton */
  166.             BM_SETCHECK,                /* Set it to pressed */
  167.             MPFROMSHORT(TRUE),
  168.             (MPARAM)NULL);
  169.     if(SessionData.PgmControl & SSF_CONTROL_MINIMIZE)
  170.         WinSendDlgItemMsg(
  171.             hwndDlg,
  172.             PIRB_MINIMIZED,             /* Program style: Minimized radiobutton */
  173.             BM_SETCHECK,                /* Set it to pressed */
  174.             MPFROMSHORT(TRUE),
  175.             (MPARAM)NULL);
  176.     if(SessionData.PgmControl & SSF_CONTROL_INVISIBLE)
  177.         WinSendDlgItemMsg(
  178.             hwndDlg,
  179.             PIRB_INVISIBLE,             /* Program style: Invisible checkbox */
  180.             BM_SETCHECK,                /* Set it to pressed */
  181.             MPFROMSHORT(TRUE),
  182.             (MPARAM)NULL);
  183.     if(SessionData.PgmControl & SSF_CONTROL_NOAUTOCLOSE)
  184.         WinSendDlgItemMsg(
  185.             hwndDlg,
  186.             PIRB_NOAUTOCLOSE,           /* Program style: NoAutoClose checkbox */
  187.             BM_SETCHECK,                /* Set it to pressed */
  188.             MPFROMSHORT(TRUE),
  189.             (MPARAM)NULL);
  190.     if(SessionData.FgBg & SSF_FGBG_BACK)
  191.         WinSendDlgItemMsg(
  192.             hwndDlg,
  193.             PIRB_BACKGROUND,            /* Program style: Background checkbox */
  194.             BM_SETCHECK,                /* Set it to pressed */
  195.             MPFROMSHORT(TRUE),
  196.             (MPARAM)NULL);
  197. /*                                                                                      *\
  198.  * Now we preselect the radiobutton in the Program Priority group to the state          *
  199.  * indicated by the SessionData structure.                                              *
  200. \*                                                                                      */
  201.     WinSendMsg(hwndDlg, WM_SETUPPROGRAMPRIORITY,
  202.         MPFROMLONG(SessionData.PriorityClass), MPFROMLONG(SessionData.PriorityDelta));
  203. /*                                                                                      *\
  204.  * Now we preselect the radiobutton in the Program Size & Position group to the state   *
  205.  * indicated by the SessionData structure.                                              *
  206. \*                                                                                      */
  207.     if(SessionData.PgmControl & SSF_CONTROL_SETPOS)
  208.         {                               /* If requested select it for the first time */
  209.         WinSendDlgItemMsg(hwndDlg, PIRB_SIZEPOSITION, BM_SETCHECK,
  210.             MPFROMSHORT(TRUE), (MPARAM)NULL);
  211.         WinSendMsg(hwndDlg, WM_SETUPSIZEPOSITION,
  212.             MPFROMSHORT(TRUE), MPFROMSHORT(TRUE));
  213.         }
  214.     else
  215.         WinSendMsg(hwndDlg, WM_SETUPSIZEPOSITION,
  216.             MPFROMSHORT(FALSE), MPFROMSHORT(TRUE));
  217. /*                                                                                      *\
  218.  * Subclass dialog window procedure to catch drag & drop messages of the dialog window, *
  219.  * which doesn't contain any child windows of it (entryfields, buttons, text fields).   *
  220. \*                                                                                      */
  221.                                         /* Subclass window procedure for drag & drop support
  222.                                            save the old procedure, because the subclassing procedure
  223.                                            must call the subclassed dialog procedure for all
  224.                                            messages it doesn't handle itself, i.e. all but drag & drop */
  225.     PI_ClassDialogProcedure=WinSubclassWindow(hwndDlg, PI_SubclassedDialogProcedure);
  226.     break;
  227.     }
  228.  
  229. /*                                                                                      *\
  230.  * Syntax: WM_SETUPPROGRAMTYPE, (USHORT SessionType), NULL                              *                                           *
  231. \*                                                                                      */
  232. case WM_SETUPPROGRAMTYPE:
  233. /*                                                                                      *\
  234.  * Adjust the Program Type radiobuttons by selecting only the button corresponding to   *
  235.  * the SessionType.                                                                     *
  236. \*                                                                                      */
  237.     {                                   /* Radiobutton IDs sorted */
  238.     USHORT      usSessionTypeRBs[]={PIRB_SHELL, PIRB_OS2FULLSCREEN, PIRB_OS2WINDOW,
  239.                                     PIRB_PM, PIRB_DOSFULLSCREEN, PIRB_DOSWINDOW,
  240.                                     PIRB_WPSOBJECT};
  241.                                         /* Corresponding session type IDs sorted */
  242.     USHORT      usSessionTypeIDs[]={SSF_TYPE_DEFAULT, SSF_TYPE_FULLSCREEN, SSF_TYPE_WINDOWABLEVIO,
  243.                                     SSF_TYPE_PM, SSF_TYPE_VDM, SSF_TYPE_WINDOWEDVDM,
  244.                                     SSF_TYPE_WPSOBJECT};
  245.     USHORT      usSessionType=SHORT1FROMMP(mp1);
  246.     USHORT      usTemp;
  247.                                         /* Loop for all buttons and deselect all but the
  248.                                            one specified in usSessionType */
  249.     for(usTemp=0; usTemp<=(sizeof(usSessionTypeRBs)/sizeof(USHORT)); usTemp++)
  250.         if(usSessionTypeIDs[usTemp]==usSessionType)
  251.             {
  252.             WinSendDlgItemMsg(          /* Send message to one Program Type radiobutton,
  253.                                            this only updates the radiobutton but doesn't
  254.                                            create a WM_CONTROL message */
  255.                 hwndDlg,                /* Handle of dialog window */
  256.                                         /* Program type radiobutton */
  257.                 usSessionTypeRBs[usTemp],
  258.                 BM_SETCHECK,            /* Set it to pressed */
  259.                 MPFROMSHORT(TRUE),
  260.                 (MPARAM)NULL);
  261.                                         /* Simulate the click to update the dialog's child windows */
  262.             WinSendMsg(hwndDlg, WM_CONTROL,
  263.                 MPFROM2SHORT(usSessionTypeRBs[usTemp], BN_CLICKED), (MPARAM)NULL);
  264.             }
  265.                                         /* Hide DOS Settings window until the application
  266.                                            type is DOS Window or DOS Fullscreen */
  267.     if(usSessionType==SSF_TYPE_WPSOBJECT)
  268.         {
  269.                                         /* Only default priority is allowed for WPS Objects */
  270.         WinSendMsg(hwndDlg, WM_SETUPPROGRAMPRIORITY,
  271.             MPFROMLONG(PIRB_NOCHANGE), MPFROMLONG(SessionData.PriorityDelta));
  272.                                         /* Only default Style is allowed */
  273.         WinSendDlgItemMsg(hwndDlg, PIRB_DEFAULTSTYLE, BM_SETCHECK,
  274.             MPFROMSHORT(TRUE), (MPARAM)NULL);
  275.         }
  276.     }
  277.     break;
  278.  
  279. /*                                                                                      *\
  280.  * Syntax: WM_SETPROGRAMPRIORITY, (ULONG PriorityClass), (LONG PriorityDelta)           *                                           *
  281. \*                                                                                      */
  282. case WM_SETUPPROGRAMPRIORITY:
  283. /*                                                                                      *\
  284.  * Adjust the Program Priotiry radiobuttons by selecting only the button corresponding  *
  285.  * to the PriorityClass and select the PriorityDelta listbox.                           *
  286. \*                                                                                      */
  287.     {                                   /* Radiobutton IDs sorted */
  288.     ULONG       ulPriorityClassRBs[]={PIRB_NOCHANGE, PIRB_IDLETIME, PIRB_REGULAR,
  289.                                       PIRB_TIMECRITICAL, PIRB_FOREGROUNDSERVER};
  290.                                         /* Corresponding priority class IDs sorted */
  291.     ULONG       ulPriorityClassIDs[]={PRTYC_NOCHANGE, PRTYC_IDLETIME, PRTYC_REGULAR,
  292.                                       PRTYC_TIMECRITICAL, PRTYC_FOREGROUNDSERVER};
  293.     ULONG       ulPriorityClass=LONGFROMMP(mp1);
  294.     LONG        lPriorityDelta=LONGFROMMP(mp2);
  295.     USHORT      usTemp;
  296.     UCHAR       ucBuffer[4];
  297.     SHORT       sLoopCount;
  298.  
  299.                                         /* Loop for all buttons and deselect all but the
  300.                                            one specified in usSessionType */
  301.     for(usTemp=0; usTemp<=(sizeof(ulPriorityClassRBs)/sizeof(ULONG)); usTemp++)
  302.         if(ulPriorityClassIDs[usTemp]==ulPriorityClass)
  303.             WinSendDlgItemMsg(          /* Send message to Priority Class radiobutton */
  304.                 hwndDlg,                /* Handle of dialog window */
  305.                                         /* Program priority radiobutton */
  306.                 ulPriorityClassRBs[usTemp],
  307.                 BM_SETCHECK,            /* Set it to pressed */
  308.                 MPFROMSHORT(TRUE),
  309.                 (MPARAM)NULL);
  310. /*                                                                                      *\
  311.  * Now we preselect the listbox in the Program priority group to the state indicated by *
  312.  * the SessionData structure.                                                           *
  313. \*                                                                                      */
  314.     for(sLoopCount=PRTYD_MAXIMUM; sLoopCount>=PRTYD_MINIMUM; sLoopCount--)
  315.         {
  316.         sprintf(ucBuffer, "%+2d", sLoopCount);
  317.         WinInsertLboxItem(              /* Insert an item to listbos */
  318.                                         /* List box handle */
  319.             WinWindowFromID(hwndDlg, PILB_DELTAPRIORITY),
  320.             LIT_END,                    /* Insert at end */
  321.             ucBuffer);                  /* Text to be inserted */
  322.         }
  323.     WinSendDlgItemMsg(                  /* Send message to Delta Priority listbox */
  324.         hwndDlg,                        /* Handle of dialog window */
  325.         PILB_DELTAPRIORITY,
  326.         LM_SELECTITEM,                  /* Set selection of an item */
  327.                                         /* Select value for PriorityDelta */
  328.         MPFROMSHORT(PRTYD_MAXIMUM-lPriorityDelta),
  329.         MPFROMSHORT(TRUE));
  330.     WinSendDlgItemMsg(                  /* Send message to Delta Priority listbox */
  331.         hwndDlg,                        /* Handle of dialog window */
  332.         PILB_DELTAPRIORITY,
  333.         LM_SETTOPINDEX,                 /* Set default selection to top of the list box */
  334.         MPFROMSHORT(PRTYD_MAXIMUM-lPriorityDelta),
  335.         (MPARAM)NULL);
  336.     }
  337.     break;
  338.  
  339. /*                                                                                      *\
  340.  * Syntax: WM_SETUPSIZEPOSITION, (BOOL bWriteable), (BOOL bInsert)                      *
  341. \*                                                                                      */
  342. case WM_SETUPSIZEPOSITION:
  343. /*                                                                                      *\
  344.  * The 4 entryfields for the Size&Position are a bit more complicated to handle.        *
  345.  * First we set the entryfields to a size of 4 and the default values are read from the *
  346.  * SessionData structure. Only if Size&Position is selected, this 4 entryfields are not *
  347.  * readonly. Flag bWriteable is true if Size&Position is selected, Flag bInsert is true *
  348.  * if we write the values the first time.                                               *
  349. \*                                                                                      */
  350.     {
  351.     USHORT      usSizePositionEFs[]={PIEF_X, PIEF_Y, PIEF_XSIZE, PIEF_YSIZE};
  352.     BOOL        bWriteable=SHORT1FROMMP(mp1);
  353.     BOOL        bInsert=SHORT1FROMMP(mp2);
  354.     USHORT      usTemp;
  355.     USHORT      *pusSizePosition;
  356.     UCHAR       ucBuffer[4];
  357.  
  358.                                         /* Get first Size & Position value */
  359.     pusSizePosition=&SessionData.InitXPos;
  360.                                         /* Loop for all entryfields and enable and insert
  361.                                            values into them */
  362.     for(usTemp=0; usTemp<=(sizeof(usSizePositionEFs)/sizeof(USHORT));
  363.         usTemp++, pusSizePosition++)
  364.         {
  365.         if(bWriteable==TRUE)            /* If writeable, enable them */
  366.             WinSendDlgItemMsg(          /* Send message to entryfield */
  367.                 hwndDlg,
  368.                                         /* Program size & position entryfield */
  369.                 usSizePositionEFs[usTemp],
  370.                 EM_SETREADONLY,         /* Set to enable read/write */
  371.                 MPFROMSHORT(FALSE),
  372.                 (MPARAM)NULL);
  373.         else
  374.             WinSendDlgItemMsg(          /* Send message to entryfield */
  375.                 hwndDlg,
  376.                                         /* Program size & position entryfield */
  377.                 usSizePositionEFs[usTemp],
  378.                 EM_SETREADONLY,         /* Set to enable readonly */
  379.                 MPFROMSHORT(TRUE),
  380.                 (MPARAM)NULL);
  381.         if(bInsert==TRUE)               /* If initializing, insert them */
  382.             {
  383.             WinSendDlgItemMsg(          /* Send message to dialog window */
  384.                 hwndDlg,                /* Handle of dialog window */
  385.                                         /* Program size: X entryfield */
  386.                 usSizePositionEFs[usTemp],
  387.                 EM_SETTEXTLIMIT,        /* Set text limit to 4 */
  388.                 MPFROMSHORT(4),
  389.                 (MPARAM)NULL);
  390.             WinSetDlgItemText(          /* Set a text string in a dialog item */
  391.                 hwndDlg,
  392.                 usSizePositionEFs[usTemp],
  393.                 (UCHAR *)_itoa(*pusSizePosition, ucBuffer, 10));
  394.             }
  395.         }
  396.     }
  397.     break;
  398.  
  399. case WM_HELP:                           /* Help pressed */
  400.     if(hwndHelp!=NULLHANDLE) WinSendMsg(
  401.         hwndHelp,                       /* Help window */
  402.         HM_DISPLAY_HELP,                /* Display a help panel */
  403.                                         /* Panel ID in ressource file */
  404.         MPFROMSHORT(PIID_PROGRAMDIALOG),
  405.         HM_RESOURCEID);                 /* MP1 points to the help window identity */
  406.     break;
  407.  
  408. case WM_CONTROL:                        /* Test for autoradio buttons pressed */
  409. /*                                                                                      *\
  410.  * The Size & Position radiobutton must be checked every time it is selected, because   *
  411.  * only if it is selected, the user may have write access to X, Y, Size X and Size Y    *
  412.  * entryfields, otherwise they are read only. The DOS Setting MLE is only visible if a  *
  413.  * DOS window or fullscreen application type is selected.                               *
  414. \*                                                                                      */
  415.     {                                   /* Child windows that change with the
  416.                                            PIRB_WPSOBJECT radiobutton */
  417.     USHORT      usChild2WPSObject[]={PIRB_MAXIMIZED, PIRB_MINIMIZED, PIRB_SIZEPOSITION,
  418.                                      PIRB_INVISIBLE, PIRB_NOAUTOCLOSE, PIRB_BACKGROUND,
  419.                                      PIEF_X, PIEF_Y, PIEF_XSIZE, PIEF_YSIZE,
  420.                                      /*PIRB_IDLETIME, PIRB_REGULAR,*/ /*PIRB_NOCHANGE,*/
  421.                                      /*PIRB_TIMECRITICAL, PIRB_FOREGROUNDSERVER,
  422.                                      PILB_DELTAPRIORITY, PICB_CHILDPROCESS*/};
  423.                                         /* Hide the following for WPS Objects */
  424.     USHORT      usChild2WPSObjectHide[]={PIEF_DIRECTORY, PIEF_PARAMETERS};
  425.                                         /* Child window that change with a DOS radiobutton */
  426.     USHORT      usChild2DOS[]={PIEF_DOSSETTINGS};
  427.  
  428.     if(SHORT2FROMMP(mp1)==BN_CLICKED)   /* Was autoradio button clicked ? */
  429.         switch(SHORT1FROMMP(mp1))
  430.         {
  431.         case PIRB_SIZEPOSITION:         /* Program type: User defined size & position */
  432.             if((BOOL)WinSendDlgItemMsg( /* Send message to Size & Position radiobutton */
  433.                 hwndDlg,                /* Handle of dialog window */
  434.                 PIRB_SIZEPOSITION,      /* Program size: Size & Position radiobutton */
  435.                 BM_QUERYCHECK,          /* Query the state */
  436.                 (MPARAM)NULL,
  437.                 (MPARAM)NULL)==TRUE)
  438.                 WinSendMsg(hwndDlg, WM_SETUPSIZEPOSITION,
  439.                     MPFROMSHORT(TRUE), MPFROMSHORT(FALSE));
  440.             else
  441.                 WinSendMsg(hwndDlg, WM_SETUPSIZEPOSITION,
  442.                     MPFROMSHORT(FALSE), MPFROMSHORT(FALSE));
  443.             break;
  444.  
  445.         case PIRB_DOSFULLSCREEN:
  446.         case PIRB_DOSWINDOW:
  447.                                         /* Enable and show DOS child windows */
  448.             DisableDialogItem(hwndDlg, usChild2DOS,
  449.                 sizeof(usChild2DOS)/sizeof(USHORT), WS_VISIBLE);
  450.                                         /* Enable and show WPSObject child windows */
  451.             DisableDialogItem(hwndDlg, usChild2WPSObject,
  452.                 sizeof(usChild2WPSObject)/sizeof(USHORT), WS_VISIBLE);
  453.                                         /* Enable and show WPSObject child windows */
  454.             DisableDialogItem(hwndDlg, usChild2WPSObjectHide,
  455.                 sizeof(usChild2WPSObjectHide)/sizeof(USHORT), WS_VISIBLE);
  456.             break;
  457.  
  458.         case PIRB_SHELL:
  459.         case PIRB_OS2FULLSCREEN:
  460.         case PIRB_OS2WINDOW:
  461.         case PIRB_PM:
  462.                                         /* Enable and hide DOS child windows */
  463.             DisableDialogItem(hwndDlg, usChild2DOS,
  464.                 sizeof(usChild2DOS)/sizeof(USHORT), 0);
  465.                                         /* Enable and show WPSObject child windows */
  466.             DisableDialogItem(hwndDlg, usChild2WPSObject,
  467.                 sizeof(usChild2WPSObject)/sizeof(USHORT), WS_VISIBLE);
  468.                                         /* Enable and show WPSObject child windows */
  469.             DisableDialogItem(hwndDlg, usChild2WPSObjectHide,
  470.                 sizeof(usChild2WPSObjectHide)/sizeof(USHORT), WS_VISIBLE);
  471.             break;
  472.         
  473.         case PIRB_WPSOBJECT:
  474.                                         /* Disable and show WPSObject child windows */
  475.             DisableDialogItem(hwndDlg, usChild2WPSObject,
  476.                 sizeof(usChild2WPSObject)/sizeof(USHORT), WS_VISIBLE | WS_DISABLED);
  477.                                         /* Hide but enable WPSObject child windows */
  478.             DisableDialogItem(hwndDlg, usChild2WPSObjectHide,
  479.                 sizeof(usChild2WPSObjectHide)/sizeof(USHORT), 0);
  480.                                         /* Enable and hide DOS child windows */
  481.             DisableDialogItem(hwndDlg, usChild2DOS,
  482.                 sizeof(usChild2DOS)/sizeof(USHORT), 0);
  483.                                         /* Only default priority is allowed for WPS Objects */
  484.             WinSendMsg(hwndDlg, WM_SETUPPROGRAMPRIORITY,
  485.                 MPFROMLONG(PIRB_NOCHANGE), MPFROMLONG(SessionData.PriorityDelta));
  486.                                         /* Only default Style is allowed */
  487.             WinSendDlgItemMsg(hwndDlg, PIRB_DEFAULTSTYLE, BM_SETCHECK,
  488.                 MPFROMSHORT(TRUE), (MPARAM)NULL);
  489.                                         /* Load empty text in not required fields */
  490.             WinSetDlgItemText(hwndDlg, PIEF_DIRECTORY, "");
  491.             WinSetDlgItemText(hwndDlg, PIEF_PARAMETERS, "");
  492.             break;
  493.         }
  494.     }
  495.     break;
  496.  
  497. case WM_COMMAND:                        /* Button pressed */
  498.     switch(SHORT1FROMMP(mp1))
  499.     {
  500.     case PIPB_WINFILEDLG:               /* Locate file by standard file dialog */
  501. /*                                                                                      *\
  502.  * The user selected the File Find pushbutton to get the standard file dialog to find   *
  503.  * the program he wants to install.                                                     *
  504. \*                                                                                      */
  505.         {
  506.         FILEDLG fdFileDlg;              /* Standard file dialog control */
  507.         HWND    hwndFileDlg;            /* Handle of standard file dialog */
  508.  
  509.                                         /* Clear out structure */
  510.         memset(&fdFileDlg, 0, sizeof(FILEDLG));
  511.                                         /* Structure size */
  512.         fdFileDlg.cbSize=sizeof(FILEDLG);
  513.                                         /* FDS_* flags */
  514.         fdFileDlg.fl=FDS_CENTER | FDS_OPEN_DIALOG | FDS_PRELOAD_VOLINFO;
  515.                                         /* Dialog title string */
  516.         fdFileDlg.pszTitle="PC/2 File Search";
  517.                                         /* Initial path, filename or file filter */
  518.         strcpy(fdFileDlg.szFullFile, "C:\\*");
  519.                                         /* Open the standard file dialog ...*/
  520.         hwndFileDlg=WinFileDlg(HWND_DESKTOP, hwndDlg, &fdFileDlg);
  521.         if(hwndFileDlg && (fdFileDlg.lReturn==DID_OK))
  522.                                         /* Load the values of the standard file dialog to
  523.                                            the corresponding entryfield in the Program
  524.                                            installation dialog. It is a file not an object. */
  525.             InstallFilename2Dialog(hwndDlg, fdFileDlg.szFullFile, FALSE);
  526.         }
  527.                                         /* Prevent to dismiss program installation dialog
  528.                                            by exiting switch via a break statement */
  529.         return((MRESULT)FALSE);
  530.  
  531.     case DID_OK:                        /* Enter key pressed */
  532. /*                                                                                      *\
  533.  * Query the Program Title, Filename, Parameters and DOS Settings and copy them to the  *
  534.  * corresponding entries in the StartSession structure.                                 *
  535. \*                                                                                      */
  536.         WinQueryWindowText(             /* Query data entered in Program title entry */
  537.             WinWindowFromID(hwndDlg, PIEF_PROGRAMTITLE),
  538.                                         /* into SessionData structure */
  539.             sizeof(SessionData.PgmTitle),
  540.             SessionData.PgmTitle);
  541.         WinQueryWindowText(             /* Query data entered in Path and Filename entry */
  542.             WinWindowFromID(hwndDlg, PIEF_PATHFILENAME),
  543.                                         /* into SessionData structure */
  544.             sizeof(SessionData.PgmName),
  545.             SessionData.PgmName);
  546.         WinQueryWindowText(             /* Query data entered in working Directory entry */
  547.             WinWindowFromID(hwndDlg, PIEF_DIRECTORY),
  548.                                         /* into SessionData structure */
  549.             sizeof(SessionData.PgmDirectory),
  550.             SessionData.PgmDirectory);
  551.         WinQueryWindowText(         /* Query data entered in Parameters entry */
  552.             WinWindowFromID(hwndDlg, PIEF_PARAMETERS),
  553.                                         /* into SessionData structure */
  554.             sizeof(SessionData.PgmInputs),
  555.             SessionData.PgmInputs);
  556.         WinQueryWindowText(             /* Query data entered in DOS Settings MLE */
  557.             WinWindowFromID(hwndDlg, PIEF_DOSSETTINGS),
  558.                                         /* into SessionData structure */
  559.             sizeof(SessionData.PgmDosSettings),
  560.             SessionData.PgmDosSettings);
  561. /*                                                                                      *\
  562.  * Query the Program Type radiobuttons and set the corresponding bit into the           *
  563.  * StartSession structure. No change or the default selection are preselected during    *
  564.  * WM_INITDLG. It must be one of them set, so we don't need else parts for if-else.     *
  565. \*                                                                                      */
  566.                                         /* Program type: WPS default */
  567.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_SHELL))
  568.             SessionData.SessionType=SSF_TYPE_DEFAULT;
  569.                                         /* Program type: OS/2 Fullscreen */
  570.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_OS2FULLSCREEN))
  571.             SessionData.SessionType=SSF_TYPE_FULLSCREEN;
  572.                                         /* Program type: OS/2 Window */
  573.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_OS2WINDOW))
  574.             SessionData.SessionType=SSF_TYPE_WINDOWABLEVIO;
  575.                                         /* Program type: PM */
  576.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_PM))
  577.             SessionData.SessionType=SSF_TYPE_PM;
  578.                                         /* Program type: DOS Fullscreen */
  579.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_DOSFULLSCREEN))
  580.             SessionData.SessionType=SSF_TYPE_VDM;
  581.                                         /* Program type: DOS Window */
  582.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_DOSWINDOW))
  583.             SessionData.SessionType=SSF_TYPE_WINDOWEDVDM;
  584.                                         /* Program type: WPS Object */
  585.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_WPSOBJECT))
  586.             SessionData.SessionType=SSF_TYPE_WPSOBJECT;
  587. /*                                                                                      *\
  588.  * Query Program Style radiobuttons and set the corresponding bits in the StartSession  *
  589.  * structure. No change or the default selection are preselected during WM_INITDLG.     *
  590. \*                                                                                      */
  591.                                         /* Program style: Maximized */
  592.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_MAXIMIZED))
  593.             SessionData.PgmControl|=SSF_CONTROL_MAXIMIZE;
  594.         else
  595.             SessionData.PgmControl&=(~SSF_CONTROL_MAXIMIZE);
  596.                                         /* Program style: Minimized */
  597.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_MINIMIZED))
  598.             SessionData.PgmControl|=SSF_CONTROL_MINIMIZE;
  599.         else
  600.             SessionData.PgmControl&=(~SSF_CONTROL_MINIMIZE);
  601.                                         /* Program style: Invisible */
  602.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_INVISIBLE))
  603.             SessionData.PgmControl|=SSF_CONTROL_INVISIBLE;
  604.         else
  605.             SessionData.PgmControl&=(~SSF_CONTROL_INVISIBLE);
  606.                                         /* Program style: No autoclose */
  607.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_NOAUTOCLOSE))
  608.             SessionData.PgmControl|=SSF_CONTROL_NOAUTOCLOSE;
  609.         else
  610.             SessionData.PgmControl&=(~SSF_CONTROL_NOAUTOCLOSE);
  611.                                         /* Program style: Background */
  612.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_BACKGROUND))
  613.             SessionData.FgBg|=SSF_FGBG_BACK;
  614.         else
  615.             SessionData.FgBg&=(~SSF_FGBG_BACK);
  616. /*                                                                                      *\
  617.  * Query Size & Position radiobutton, set the corresponding bit, and load the values    *
  618.  * from the corresponding entryfields for the StartSession structure.                   *
  619. \*                                                                                      */
  620.         {
  621.         UCHAR   Buffer[4];
  622.  
  623.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_SIZEPOSITION))
  624.             SessionData.PgmControl|=SSF_CONTROL_SETPOS;
  625.         else
  626.             SessionData.PgmControl&=(~SSF_CONTROL_SETPOS);
  627.         WinQueryWindowText(             /* Query data entered in Parameters entry */
  628.             WinWindowFromID(hwndDlg, PIEF_X),
  629.                                         /* into temporary structure */
  630.             sizeof(Buffer),
  631.             Buffer);
  632.         SessionData.InitXPos=(USHORT)atol(Buffer);
  633.         WinQueryWindowText(
  634.             WinWindowFromID(hwndDlg, PIEF_Y),
  635.             sizeof(Buffer),
  636.             Buffer);
  637.         SessionData.InitYPos=(USHORT)atol(Buffer);
  638.         WinQueryWindowText(
  639.             WinWindowFromID(hwndDlg, PIEF_XSIZE),
  640.             sizeof(Buffer),
  641.             Buffer);
  642.         SessionData.InitXSize=(USHORT)atol(Buffer);
  643.         WinQueryWindowText(
  644.             WinWindowFromID(hwndDlg, PIEF_YSIZE),
  645.             sizeof(Buffer),
  646.             Buffer);
  647.         SessionData.InitYSize=(USHORT)atol(Buffer);
  648.         }
  649. /*                                                                                      *\
  650.  * Query Program Priority radiobuttons and set the corresponding bits in the            *
  651.  * StartSession structure. The default priority is No-Change. The listbox is also       *
  652.  * queried and the Delta Priority is also set in the StartSession structure. It must be *
  653.  * one of the radiobuttons, so else part of if-else is not required.                    *
  654. \*                                                                                      */
  655.                                         /* Program Priority: No-Change */
  656.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_NOCHANGE))
  657.             SessionData.PriorityClass=PRTYC_NOCHANGE;
  658.                                         /* Program Priority: Idle-time */
  659.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_IDLETIME))
  660.             SessionData.PriorityClass=PRTYC_IDLETIME;
  661.                                         /* Program Priority: Regular */
  662.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_REGULAR))
  663.             SessionData.PriorityClass=PRTYC_REGULAR;
  664.                                         /* Program Priority: Time-critical */
  665.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_TIMECRITICAL))
  666.             SessionData.PriorityClass=PRTYC_TIMECRITICAL;
  667.                                         /* Program Priority: Server */
  668.         if(WinQueryButtonCheckstate(hwndDlg, PIRB_FOREGROUNDSERVER))
  669.             SessionData.PriorityClass=PRTYC_FOREGROUNDSERVER;
  670.                                         /* Query index of selected item on correct it */
  671.         SessionData.PriorityDelta=(
  672.             WinQueryLboxSelectedItem(
  673.                 WinWindowFromID(hwndDlg, PILB_DELTAPRIORITY))
  674.             -PRTYD_MAXIMUM)*(-1);
  675.         DialogResult=DID_OK;            /* Dialog terminated with DID_OK */
  676.         break;
  677.  
  678.     case DID_CANCEL:                    /* Escape or Cancel pressed */
  679.         DialogResult=DID_CANCEL;        /* Dialog terminated with DID_CANCEL */
  680.         break;
  681.  
  682.     default:
  683.         return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  684.     }
  685.     WinDismissDlg(hwndDlg, TRUE);       /* Clear up dialog */
  686.     break;
  687.  
  688. default:                                /* Default window procedure must be called */
  689.     return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  690. }
  691. return((MRESULT)FALSE);                 /* We have handled the message */
  692. }
  693.  
  694.  
  695. /*--------------------------------------------------------------------------------------*\
  696.  * This dialog procedure handles the subclassed PC/2 - Program Installation dialog.     *
  697.  * Req:                                                                                 *
  698.  *      SessionData ... a structure of type SESSIONDATA where the information entered   *
  699. \*--------------------------------------------------------------------------------------*/
  700. MRESULT  EXPENTRY PI_SubclassedDialogProcedure(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  701. {
  702. PDRAGINFO       pDragInfo;              /* Pointer to DRAGINFO structure */
  703. PDRAGITEM       pDragItem;              /* Pointer to DRAGITEM structure */
  704.  
  705. switch(msg)
  706. {
  707. /*                                                                                      *\
  708.  * Allow objects to be dropped on dialog box to add first dragitem as an application.   *
  709. \*                                                                                      */
  710. case DM_DRAGOVER:
  711.     pDragInfo = (PDRAGINFO)mp1;         /* Get the pointer to the DRAGINFO structure */
  712.                                         /* Access the structure */
  713.     if(DrgAccessDraginfo(pDragInfo)==FALSE) break;
  714.                                         /* Get the first itemp of the item(s) dragged
  715.                                            onto dialog window */
  716.     pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
  717.     if(pDragInfo->cditem!=1)
  718.                                         /* Don't allow dropping of more than one item */
  719.         return(MPFROM2SHORT(DOR_NODROP, DO_UNKNOWN));
  720.     else
  721.                                         /* Allow drop of undefined operation onto dialog window */
  722.         return(MPFROM2SHORT(DOR_DROP, DO_UNKNOWN));
  723.  
  724. case DM_DROP:
  725.     {
  726.     UCHAR       ucBuffer[256];
  727.     UCHAR       ucObjectType[256];
  728.     UCHAR       *pucBuffer;
  729.  
  730.     pDragInfo = (PDRAGINFO)mp1;         /* Get the pointer to the DRAGINFO structure */
  731.                                         /* Access the structure */
  732.     if(DrgAccessDraginfo(pDragInfo)==FALSE) break;
  733.                                         /* Get the first itemp of the item(s) dragged
  734.                                            onto dialog window */
  735.     pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
  736.                                         /* Query the rendering format */
  737.     DrgQueryStrName(pDragItem->hstrRMF, sizeof(ucObjectType), ucObjectType);
  738.                                         /* Scan for an WPS object */
  739.     if(strstr(ucObjectType, "<DRM_OBJECT, DRF_OBJECT>")==NULL)
  740.         {                               /* It is an application to get path and filename */
  741.                                         /* Query path (container) */
  742.         DrgQueryStrName(pDragItem->hstrContainerName, sizeof(ucBuffer), ucBuffer);
  743.                                         /* Position to \0 of path */
  744.         pucBuffer=ucBuffer+strlen(ucBuffer);
  745.                                         /* Query filename and append it to path */
  746.         DrgQueryStrName(pDragItem->hstrSourceName, sizeof(ucBuffer)-strlen(pucBuffer), pucBuffer);
  747.                                         /* Now change the entryfields to the dropped object
  748.                                            which is not a WPS object */
  749.         InstallFilename2Dialog(hwnd, ucBuffer, FALSE);
  750.         }
  751.     else
  752.         {                               /* It is an WPS Object so only get object name */
  753.                                         /* Query filename but don't append it to path */
  754.         DrgQueryStrName(pDragItem->hstrSourceName, sizeof(ucBuffer), ucBuffer);
  755.                                         /* Now change the entryfields to the dropped object
  756.                                            which is a WPS object */
  757.         InstallFilename2Dialog(hwnd, ucBuffer, TRUE);
  758.         }
  759.     }
  760.     break;
  761.  
  762. default:                                /* Pass all other messages to default window procedure */
  763.     return((MRESULT)PI_ClassDialogProcedure(hwnd, msg, mp1, mp2));
  764. }
  765. }
  766.  
  767. /*--------------------------------------------------------------------------------------*\
  768.  * This dialog procedure handles the PC/2 - Menu Installation dialog.                   *
  769.  * Req:                                                                                 *
  770.  *      SessionData ... a structure of type SESSIONDATA where the information entered   *
  771.  *                      in the dialog is entered. If DID_OK is pressed this structure   *
  772.  *                      is used to start the session and set its priority.              *
  773. \*--------------------------------------------------------------------------------------*/
  774. MRESULT  EXPENTRY MI_DialogProcedure(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  775. {
  776. switch(msg)
  777. {
  778. case WM_INITDLG:
  779.     {
  780.     SWP         swp;
  781.  
  782.     WinQueryWindowPos(                  /* Query position of dialog window */
  783.         hwndDlg,                        /* Handle of dialog window */
  784.         &swp);                          /* Fill with position */
  785.     WinSetWindowPos(                    /* Set dialog window position */
  786.         hwndDlg,                        /* Handle of dialog window */
  787.         HWND_TOP,                       /* Position on top and center of DESKTOP */
  788.         (swpScreen.cx-swp.cx)/2, (swpScreen.cy-swp.cy)/2, 0, 0, SWP_MOVE);
  789. /*                                                                                      *\
  790.  * Set the maximum number of chars accepted from the entryfield (thus overwriting the   *
  791.  * default number of 63.                                                                *
  792. \*                                                                                      */
  793.     WinSendDlgItemMsg(                  /* Send message to dialog window */
  794.         hwndDlg,                        /* Handle of dialog window */
  795.         MIEF_MENUTITLE,                 /* Program submenu title entryfield */
  796.         EM_SETTEXTLIMIT,                /* Set text limit to 60 */
  797.         MPFROMSHORT(EF_SIZE60),
  798.         (MPARAM)NULL);                  /* No additional parameter */
  799.     WinSetDlgItemText(                  /* Set text of title entryfield */
  800.         hwndDlg, MIEF_MENUTITLE, SessionData.PgmTitle);
  801.     break;
  802.     }
  803.  
  804. case WM_HELP:                           /* Help pressed */
  805.     if(hwndHelp!=NULLHANDLE) WinSendMsg(
  806.         hwndHelp,                       /* Help window */
  807.         HM_DISPLAY_HELP,                /* Display a help panel */
  808.         MPFROMSHORT(MIID_MENUDIALOG),   /* Panel ID in ressource file */
  809.         HM_RESOURCEID);                 /* MP1 points to the help window identity */
  810.     break;
  811.  
  812. case WM_COMMAND:                        /* Button pressed */
  813.     switch(SHORT1FROMMP(mp1))
  814.     {
  815.     case DID_OK:                        /* Enter key pressed */
  816. /*                                                                                      *\
  817.  * Query the Submenu Title and copy it to the corresponding entry in the StartSession   *
  818.  * structure.                                                                           *
  819. \*                                                                                      */
  820.         WinQueryWindowText(             /* Query data entered in Submenu title entry */
  821.             WinWindowFromID(hwndDlg, MIEF_MENUTITLE),
  822.                                         /* into SessionData structure */
  823.             sizeof(SessionData.PgmTitle),
  824.             SessionData.PgmTitle);
  825.         DialogResult=DID_OK;            /* Dialog terminated with DID_OK */
  826.         break;
  827.  
  828.     case DID_CANCEL:                    /* Escape or Cancel pressed */
  829.         DialogResult=DID_CANCEL;        /* Dialog terminated with DID_CANCEL */
  830.         break;
  831.  
  832.     default:
  833.         return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  834.     }
  835.     WinDismissDlg(hwndDlg, TRUE);       /* Clear up dialog */
  836.     break;
  837.  
  838. default:                                /* Default window procedure must be called */
  839.     return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  840. }
  841. return((MRESULT)FALSE);                 /* We have handled the message */
  842. }
  843.  
  844. /*--------------------------------------------------------------------------------------*\
  845.  * This dialog procedure handles the PC/2 - ShutDown OS/2 dialog.                       *
  846.  * Req: none                                                                            *
  847. \*--------------------------------------------------------------------------------------*/
  848. MRESULT  EXPENTRY SD_DialogProcedure(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  849. {
  850. switch(msg)
  851. {
  852. case WM_INITDLG:
  853.     {
  854.     SWP         swp;
  855.  
  856.     WinDefDlgProc(hwndDlg, msg, mp1, mp2);
  857.     WinQueryWindowPos(                  /* Query position of dialog window */
  858.         hwndDlg,                        /* Handle of dialog window */
  859.         &swp);                          /* Fill with position */
  860.     WinSetWindowPos(                    /* Set dialog window position */
  861.         hwndDlg,                        /* Handle of dialog window */
  862.         HWND_TOP,                       /* Position on top and center of DESKTOP */
  863.         (swpScreen.cx-swp.cx)/2, (swpScreen.cy-swp.cy)/2, 0, 0, SWP_MOVE);
  864.     WinPostMsg(hwndDlg, WM_SHUTDOWN, NULL, NULL);
  865.     break;
  866.     }
  867.  
  868. /*                                                                                      *\
  869.  * Syntax: WM_SHUTDOWN, NULL, NULL                                                      *
  870. \*                                                                                      */
  871. case WM_SHUTDOWN:
  872. /*                                                                                      *\
  873.  * Wait for 2 seconds and then shut down OS/2.                                          *
  874. \*                                                                                      */
  875.     DosSleep(02000);
  876.     DosShutdown(0);
  877.     break;
  878.  
  879. default:                                /* Default window procedure must be called */
  880.     return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  881. }
  882. return((MRESULT)FALSE);                 /* We have handled the message */
  883. }
  884.  
  885. /*--------------------------------------------------------------------------------------*\
  886.  * This dialog procedure handles the PC/2 - Startup Parameters dialog.                  *
  887.  * Req: *PgmInputs .....A pointer to a string of commandline params of an application   *
  888.  *                      via mp2                                                         *
  889. \*--------------------------------------------------------------------------------------*/
  890. MRESULT  EXPENTRY SU_DialogProcedure(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  891. {
  892. static COMMANDLINEPARAMS        *pCLPParams;
  893.  
  894. switch(msg)
  895. {
  896. case WM_INITDLG:
  897.     {
  898.     UCHAR       ucBuffer[EF_SIZE255+1];
  899.  
  900.     WinDefDlgProc(hwndDlg, msg, mp1, mp2);
  901.     pCLPParams=PVOIDFROMMP(mp2);
  902. /*                                                                                      *\
  903.  * Load text from CLPParams into the dialog box text fields, and set the text limit of  *
  904.  * the entryfield to 127.                                                               *
  905. \*                                                                                      */
  906.     sprintf(ucBuffer, "%s[...] %s", pCLPParams->ucPBefore, pCLPParams->ucPAfter);
  907.                                         /* User information text field */
  908.     WinSetDlgItemText(hwndDlg, SUTF_STARTUPINFO, pCLPParams->ucPUser);
  909.                                         /* Current parameters text field */
  910.     WinSetDlgItemText(hwndDlg, SUTF_STARTUPPARAMETERS, ucBuffer);
  911.     WinSendDlgItemMsg(hwndDlg, SUEF_STARTUPPARAMETERS, EM_SETTEXTLIMIT,
  912.         MPFROMSHORT(EF_SIZE60), (MPARAM)NULL);
  913.     break;
  914.     }
  915.  
  916. case WM_HELP:                           /* Help pressed */
  917.     if(hwndHelp!=NULLHANDLE) WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
  918.         MPFROMSHORT(SUID_STARTUPDIALOG), HM_RESOURCEID);
  919.     break;
  920.  
  921. case WM_COMMAND:                        /* Button pressed */
  922.     switch(SHORT1FROMMP(mp1))
  923.     {
  924.     case DID_OK:                        /* Enter key pressed */
  925.         WinQueryWindowText(WinWindowFromID(hwndDlg, SUEF_STARTUPPARAMETERS),
  926.             sizeof(pCLPParams->ucPUser), pCLPParams->ucPUser);
  927.         DialogResult=DID_OK;            /* Dialog terminated with DID_OK */
  928.         break;
  929.  
  930.     case DID_CANCEL:                    /* Escape or Cancel pressed */
  931.         DialogResult=DID_CANCEL;        /* Dialog terminated with DID_CANCEL */
  932.         break;
  933.  
  934.     default:
  935.         return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  936.     }
  937.     WinDismissDlg(hwndDlg, TRUE);       /* Clear up dialog */
  938.     break;
  939.  
  940. default:                                /* Default window procedure must be called */
  941.     return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  942. }
  943. return((MRESULT)FALSE);                 /* We have handled the message */
  944. }
  945.  
  946. /*--------------------------------------------------------------------------------------*\
  947.  * This dialog procedure handles the PC/2 - Resort dialog.                              *
  948. \*--------------------------------------------------------------------------------------*/
  949. MRESULT  EXPENTRY RD_DialogProcedure(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  950. {
  951. static MENUDATA *pSortedMenuData;       /* Pointer to the first element of the resorted
  952.                                            linked list */
  953. static MENUDATA *pParentMenuData;       /* Menuitem, which current level is a child of */
  954. static USHORT   usChild2InitPBs[]={DID_OK};
  955. static USHORT   usChild2MovePBs[]={DID_CANCEL};
  956. static USHORT   usChild2OKPBs[]={RDPB_MOVE};
  957. static BOOL     bFirstMove;
  958. switch(msg)
  959. {
  960. case WM_INITDLG:
  961.     {
  962.     SWP         swp;
  963.     SHORT       sCount;
  964.     MENUDATA    *pMDSource;             /* Pointer withing the current linked list */
  965.  
  966.     WinDefDlgProc(hwndDlg, msg, mp1, mp2);
  967.     WinQueryWindowPos(                  /* Query position of dialog window */
  968.         hwndDlg,                        /* Handle of dialog window */
  969.         &swp);                          /* Fill with position */
  970.     WinSetWindowPos(                    /* Set dialog window position */
  971.         hwndDlg,                        /* Handle of dialog window */
  972.         HWND_TOP,                       /* Position on top and center of DESKTOP */
  973.         (swpScreen.cx-swp.cx)/2, (swpScreen.cy-swp.cy)/2, 0, 0, SWP_MOVE);
  974. /*                                                                                      *\
  975.  * Disable OK pushbutton, until all items have been moved. Get the first element of the *
  976.  * current level of the linked list which will be resorted. Add all Menuitems of the    *
  977.  * current level of the linked list to the source listbox. Save the parent Menuitem,    *
  978.  * from where the current level is a child of.                                          *
  979. \*                                                                                      */
  980.     bFirstMove=FALSE;                   /* We didn't make any sort before */
  981.     pSortedMenuData=NULL;               /* Pointer of resorted linked list points to a non
  982.                                            available Menuitem */
  983.                                         /* Disable and show OK pushbutton */
  984.     DisableDialogItem(hwndDlg, usChild2InitPBs,
  985.         sizeof(usChild2InitPBs)/sizeof(USHORT), WS_VISIBLE | WS_DISABLED);
  986.     if(pMenuData==pPopupMenu)           /* Is current level is the root of all levels ? */
  987.         pParentMenuData=NULL;           /* Yes, then parent Menuitem is NULL */
  988.     else                                /* No, then get parent Menuitem */
  989.         pParentMenuData=pMenuData->Back;
  990.     pMDSource=pMenuData;                /* Get first element of linked list */
  991.     do                                  /* Add current level of Menuitems to the source listbox */
  992.     {
  993.         if(pMDSource->Item==ENTRYSUBMENU) /* It is a Submenu */
  994.             {
  995.             UCHAR       ucBuffer[EF_SIZE60+4];
  996.                                         /* Add >> for a Submenu */
  997.             sprintf(ucBuffer, "%s >>", pMDSource->PgmTitle);
  998.                                         /* Insert Menuitem at the end of the listbox */
  999.             WinSendDlgItemMsg(hwndDlg, RDLB_SOURCEMENU, LM_INSERTITEM,
  1000.                 MPFROMSHORT(LIT_END), MPFROMP(ucBuffer));
  1001.             }
  1002.                                         /* It's a Menuitem */
  1003.         if(pMDSource->Item==ENTRYMENUITEM)
  1004.             WinSendDlgItemMsg(hwndDlg, RDLB_SOURCEMENU, LM_INSERTITEM,
  1005.                 MPFROMSHORT(LIT_END), MPFROMP(pMDSource->PgmTitle));
  1006.                                         /* It may also be an empty entry, but then we
  1007.                                            ignore it, because it must be filled with
  1008.                                            Menuitem or Submenu data first */
  1009.         if(pMDSource->Next!=NULL)       /* Get through linked list without diving into
  1010.                                            Submenus */
  1011.                 pMDSource=pMDSource->Next;
  1012.         else break;                     /* We're at the end of the linked list */
  1013.     }while(TRUE);
  1014.     break;
  1015.     }
  1016.  
  1017. case WM_HELP:                           /* Help pressed */
  1018.     if(hwndHelp!=NULLHANDLE) WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
  1019.         MPFROMSHORT(RDID_RESORTDIALOG), HM_RESOURCEID);
  1020.     break;
  1021.  
  1022. case WM_COMMAND:                        /* Button pressed */
  1023.     switch(SHORT1FROMMP(mp1))
  1024.     {
  1025.     case RDPB_MOVE:                     /* Move pushbutton */
  1026.         {
  1027.         MENUDATA        *pMDSource;     /* Walk through current linked list */
  1028.                                         /* Walk through destination linked list */
  1029.         MENUDATA        *pMDDestination;
  1030.         SHORT           sCount;
  1031.  
  1032. /*                                                                                      *\
  1033.  * For the first resort operation, disable the Cancel pushbutton.                       *
  1034. \*                                                                                      */
  1035.         if(bFirstMove==FALSE)           /* After the first move operation, disable the
  1036.                                            Cancel pushbutton */
  1037.             {
  1038.             bFirstMove=TRUE;            /* We make now the first move */
  1039.             DisableDialogItem(hwndDlg, usChild2MovePBs,
  1040.                 sizeof(usChild2MovePBs)/sizeof(USHORT), WS_VISIBLE | WS_DISABLED);
  1041.             }
  1042. /*                                                                                      *\
  1043.  * Now get the selected Menuitem of the source listbox, delete it from the listbox. If  *
  1044.  * the source listbox is now empty, reenable the OK pushbutton again.                   *
  1045. \*                                                                                      */
  1046.                                         /* Query the selected Menuitem from the source listbox */
  1047.         sCount=(SHORT)WinSendDlgItemMsg(hwndDlg, RDLB_SOURCEMENU, LM_QUERYSELECTION,
  1048.             MPFROMSHORT(LIT_FIRST), (MPARAM)NULL);
  1049.         if(sCount==LIT_NONE)            /* If no item selected ignore this button */
  1050.             return((MRESULT)FALSE);
  1051.         {
  1052.         UCHAR   ucBuffer[EF_SIZE60+4];
  1053.         SHORT   usItems;
  1054.                                         /* Query the text of the selected Menuitem from the
  1055.                                            source listbox */
  1056.         WinSendDlgItemMsg(hwndDlg, RDLB_SOURCEMENU, LM_QUERYITEMTEXT,
  1057.             MPFROM2SHORT(sCount, sizeof(ucBuffer)), MPFROMP(ucBuffer));
  1058.                                         /* Delete the selected Menuitem from the source listbox */
  1059.         WinSendDlgItemMsg(hwndDlg, RDLB_SOURCEMENU, LM_DELETEITEM,
  1060.             MPFROMSHORT(sCount), (MPARAM)NULL);
  1061.                                         /* Insert the text of the selected Menuitem into the
  1062.                                            destination listbox */
  1063.         WinSendDlgItemMsg(hwndDlg, RDLB_DESTINATIONMENU, LM_INSERTITEM,
  1064.             MPFROMSHORT(LIT_END), MPFROMP(ucBuffer));
  1065.                                         /* Query the number of Menuitems from the source
  1066.                                            listbox */
  1067.         usItems=(USHORT)WinSendDlgItemMsg(hwndDlg, RDLB_SOURCEMENU, LM_QUERYITEMCOUNT,
  1068.             (MPARAM)NULL, (MPARAM)NULL);
  1069.         if(usItems==0)                  /* If now more items left, reenable OK pushbutton
  1070.                                            and disable Resort pushbutton */
  1071.             {
  1072.             DisableDialogItem(hwndDlg, usChild2InitPBs,
  1073.                 sizeof(usChild2InitPBs)/sizeof(USHORT), WS_VISIBLE);
  1074.             DisableDialogItem(hwndDlg, usChild2OKPBs,
  1075.                 sizeof(usChild2OKPBs)/sizeof(USHORT), WS_VISIBLE | WS_DISABLED);
  1076.             }
  1077.         }
  1078. /*                                                                                      *\
  1079.  * Now remove the selected Menuitem from the current linked list, by updating the       *
  1080.  * pointers according to previous or following Menuitems.                               *
  1081. \*                                                                                      */
  1082.         pMDSource=pMenuData;            /* Point to the first element of the linked list */
  1083.         for( ; sCount>0; sCount--)      /* Walk through the linked list to the selected
  1084.                                            item */
  1085.             pMDSource=pMDSource->Next;
  1086.         pMDDestination=pSortedMenuData; /* Point to the first element of the resorted linked list */
  1087.         if(pMDDestination!=NULL)        /* Walk through the resorted linked list to the
  1088.                                            last Menuitem, if there's at least one element */
  1089.             for( ; pMDDestination->Next!=NULL; pMDDestination=pMDDestination->Next);
  1090. /*                                                                                      *\
  1091.  * Now update the Popup-Menu, by moving the selected Menuitem.                          *
  1092. \*                                                                                      */
  1093.         if((pMDDestination==NULL) && (pParentMenuData==NULL))
  1094.             SetPopupMenu(MM_MOVEMENUITEM, MPFROMP(pMDSource), MPFROMP(pPopupMenu));
  1095.         if((pMDDestination==NULL) && (pParentMenuData!=NULL))
  1096.             SetPopupMenu(MM_MOVEMENUITEM, MPFROMP(pMDSource), MPFROMP(pParentMenuData));
  1097.         if(pMDDestination!=NULL)
  1098.             SetPopupMenu(MM_MOVEMENUITEM, MPFROMP(pMDSource), MPFROMP(pMDDestination));
  1099.  
  1100.         if((pMDSource->Back!=NULL) && (pMDSource->Next!=NULL))
  1101.             {                           /* Current element follows another and is followed
  1102.                                            by another element, so simple remove it by
  1103.                                            updating the pointers. Be carefull if the
  1104.                                            parent element is a Submenu where the current
  1105.                                            level is a leaf of. */
  1106.             if((pMDSource->Back)->Submenu==pMDSource)
  1107.                 {
  1108.                 (pMDSource->Back)->Submenu=pMDSource->Next;
  1109.                 pMenuData=pMDSource->Next;
  1110.                 }
  1111.             else
  1112.                 (pMDSource->Back)->Next=pMDSource->Next;
  1113.             (pMDSource->Next)->Back=pMDSource->Back;
  1114.             }
  1115.         if((pMDSource->Back!=NULL) && (pMDSource->Next==NULL))
  1116.             {                           /* Current element follows another but is the last
  1117.                                            one of the current linked list.  Be carefull if
  1118.                                            the parent element is a Submenu where the current
  1119.                                            level is a leaf of. */
  1120.                                         /* Next element of course is NULL */
  1121.             if((pMDSource->Back)->Submenu==pMDSource)
  1122.                 {
  1123.                 (pMDSource->Back)->Submenu=pMDSource->Next;
  1124.                 pMenuData=pMDSource->Next;
  1125.                 }
  1126.             else
  1127.                 (pMDSource->Back)->Next=pMDSource->Next;
  1128.             }
  1129.         if((pMDSource->Back==NULL) && (pMDSource->Next!=NULL))
  1130.             {                           /* Current element is the first one of the complete
  1131.                                            linked list, but is followed by another */
  1132.             (pMDSource->Next)->Back=NULL;
  1133.             pMenuData=pMDSource->Next;
  1134.             pPopupMenu=pMDSource->Next;
  1135.             }
  1136.         if((pMDSource->Back==NULL) && (pMDSource->Next==NULL))
  1137.             {                           /* Current element is the first one of the complete
  1138.                                            linked list, and isn't followed by another */
  1139.             pMenuData=NULL;
  1140.             pPopupMenu=NULL;
  1141.             }
  1142. /*                                                                                      *\
  1143.  * Now add the deleted Menuitem at the end of the resorted linked list, by updating the *
  1144.  * pointer of the last element to point to the deleted one.                             *
  1145. \*                                                                                      */
  1146.         if(pMDDestination==NULL)
  1147.             {                           /* If the resorted linked list is empty, add
  1148.                                            deleted element and update pointers */
  1149.             pSortedMenuData=pMDSource;
  1150.             pMDDestination=pMDSource;
  1151.             pMDDestination->Next=NULL;
  1152.             pMDDestination->Back=NULL;
  1153.             }
  1154.         else
  1155.             {                           /* If the resorted linked list isn't empty, add
  1156.                                            deleted element at the end and update pointers */
  1157.             pMDDestination->Next=pMDSource;
  1158.             pMDSource->Back=pMDDestination;
  1159.             pMDSource->Next=NULL;
  1160.             }
  1161.         }
  1162.         return((MRESULT)FALSE);         /* We don't want to close the dialog by breaking
  1163.                                            out of the switch statement */
  1164.  
  1165.     case DID_OK:                        /* Enter key pressed */
  1166. /*                                                                                      *\
  1167.  * Now replace the current linked list, which is empty as all Menuitems have been re-   *
  1168.  * moved, with the resorted linked list.                                                *
  1169. \*                                                                                      */
  1170.         if(pParentMenuData==NULL)
  1171.             {                           /* If the root of the complete linked list has been
  1172.                                            resorted, update the root pointers */
  1173.             pPopupMenu=pSortedMenuData;
  1174.             pMenuData=pPopupMenu;
  1175.             }
  1176.         else
  1177.             {                           /* If the current level has a parent Menuitem, a
  1178.                                            Submenu of course, update the current level pointers */
  1179.             pMenuData=pSortedMenuData;
  1180.             pSortedMenuData->Back=pParentMenuData;
  1181.             pParentMenuData->Submenu=pMenuData;
  1182.             }
  1183.         DialogResult=DID_OK;            /* Dialog terminated with DID_OK */
  1184.         break;
  1185.  
  1186.     case DID_CANCEL:                    /* Escape or Cancel pressed */
  1187.         DialogResult=DID_CANCEL;        /* Dialog terminated with DID_CANCEL */
  1188.         break;
  1189.  
  1190.     default:
  1191.         return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  1192.     }
  1193.     WinDismissDlg(hwndDlg, TRUE);       /* Clear up dialog */
  1194.     break;
  1195.  
  1196. default:                                /* Default window procedure must be called */
  1197.     return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  1198. }
  1199. return((MRESULT)FALSE);                 /* We have handled the message */
  1200. }
  1201.  
  1202.  
  1203.